#pragma once

#include <string>
#include <vector>
#include <map>
#include <functional>

#include "session.h"
#include "jansson.h"
#include "header.h"


using CMD_CB = std::function<void(std::vector<std::string>, std::vector<std::string>&)>;

struct Cmd_Param {
	char type;
};

struct Cmd_Map{
	std::string name;
	std::string desc;
	CMD_CB func;
	unsigned short psize;	//参数个数,最大4个
	Cmd_Param params[4];	//各个参数支持的类型
    std::string doc;
};

static inline std::string Print(std::string doc) {
    return "Usage:\n\t "+doc+"\n";
}
#define DOC(context) Print(context)

static std::string Request(json_t*, std::string name, Command cid);

//======================新增命令修改区=======================================
void doHelp(std::vector<std::string>, std::vector<std::string>&);
void doLs(std::vector<std::string>, std::vector<std::string>&);
void doInfo(std::vector<std::string>, std::vector<std::string>&);
void doClear(std::vector<std::string>, std::vector<std::string>&);
void doPlay(std::vector<std::string>, std::vector<std::string>&);


static std::string doc_help = "help";
static std::string doc_ls = "ls";
static std::string doc_info = "info <vid>";
static std::string doc_clear = "clear";
static std::string doc_play = "play <vid>";

static Cmd_Map CMap[] = {
	{
		"help", 
		"list this help menu",
		doHelp, 
		0, 
		{},
		DOC(doc_help)
	},
	{
		"ls", 
		"list server all videos",
		doLs, 
		0, 
		{},
		DOC(doc_ls)
	},
	{
		"info",
		"get a video information",
		doInfo,
		1,
		{'i'},
		DOC(doc_info)
	},
	{
		"clear", 
		"clear the screen",
		doClear, 
		0, 
		{},
		DOC(doc_clear)
	},
	{
		"play", 
		"play a video online",
		doPlay, 
		1, 
		{'i'},
		DOC(doc_play)
	},
};

static std::map<std::string, int> gCatag = {
	//chat功能
	{"CHAT", 0},
	//video对象功能
    {"LS", 1},
	{"INFO", 1},
	{"PLAY", 1},
	{"PLAY_START", 1}
};


